window.addEventListener('load', () => {
  // 渲染标题行 并且添加地址转换
  ajax({
    type: 'get',
    url: baseUrl + '/system/category',
    success: function (res) {
      // console.log(res)
      if (res.code != 0) {
        layer.msg(res.msg, { icon: 2 })
      }
      let data = res.data;
      let str = `<li class="layui-nav-item ">
      <a href="index.html">首页</a>
    </li>`;
      data.forEach(item => {
        str += `	<li class="layui-nav-item ">
      <a href="./list.html??id=${item.id}&name=${item.name}">${item.name}</a>
    </li>`
      })
      let title = document.querySelector('.title')
      title.innerHTML = str;

      // 发布和退出逻辑
      let token = getCookie('token');
      let html = ''
      if (token) {
        html = `<dd><a href="./article.html">发布文章</a></dd>
      <dd class='logout'><a >退出</a></dd>`
      } else {
        html = `<dd><a href="./login.html">登录</a></dd>`
      }

      document.querySelector('.loginout').innerHTML = html;
      let logout = document.querySelector('.logout');
      logout.onclick = function () {
        removeCookie('token');
        location.href = 'login.html'
      }
    }
  })
 
})